package com.ruoyi.web.controller.inv;

import com.ruoyi.buy.domain.entity.PO.InvStockBill;
import com.ruoyi.buy.domain.entity.inv0005.Inv0005InvDataDto;
import com.ruoyi.buy.domain.entity.inv0006.Inv0006InvDataDto;
import com.ruoyi.buy.domain.entity.inv0006.Inv0006UpdateByIdVO;
import com.ruoyi.buy.service.IInvStockBillService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 盘点单信息Controller
 * 
 * @author ruoyi
 * @date 2024-01-02
 */
@RestController
@RequestMapping("/inv/stockbill")
public class InvStockBillController extends BaseController
{
    @Autowired
    private IInvStockBillService invStockBillService;

    /**
     * 查询盘点单信息列表
     */

    @GetMapping("/list")
    public TableDataInfo list(InvStockBill invStockBill)
    {
        startPage();
        List<InvStockBill> list = invStockBillService.selectInvStockBillList(invStockBill);
        return getDataTable(list);
    }

    /**
     * 导出盘点单信息列表
     */

    @Log(title = "盘点单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvStockBill invStockBill)
    {
        List<InvStockBill> list = invStockBillService.selectInvStockBillList(invStockBill);
        ExcelUtil<InvStockBill> util = new ExcelUtil<InvStockBill>(InvStockBill.class);
        util.exportExcel(response, list, "盘点单信息数据");
    }

    /**
     * 获取盘点单信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(invStockBillService.selectInvStockBillById(id));
    }

    /**
     * 新增盘点单信息
     */
    @Log(title = "盘点单信息", businessType = BusinessType.INSERT)
    @PostMapping("/addStockbill")
    public AjaxResult add(@RequestBody Inv0006UpdateByIdVO para)
    {
        return toAjax(invStockBillService.insertInvStockBill(para));
    }

    /**
     * 修改盘点单信息
     */
    @Log(title = "盘点单信息", businessType = BusinessType.UPDATE)
    @PostMapping("/updateStockbill")
    public AjaxResult edit(@RequestBody Inv0006UpdateByIdVO para)
    {
        return toAjax(invStockBillService.updateInvStockBill(para));
    }

    /**
     * 删除盘点单信息
     */
    @Log(title = "盘点单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(invStockBillService.deleteInvStockBillByIds(ids));
    }

    /**
     * 查询出库单列表
     */
    @PostMapping("/getInvDataList")
    public AjaxResult getInvDataList(@RequestBody InvStockBill para)
    {

        List<Inv0006InvDataDto> list = invStockBillService.getInvDataList(para);
        return success(list);
    }

    /**
     * 查询出库单列表
     */
    @PostMapping("/viewById")
    public AjaxResult viewById(@RequestBody InvStockBill para)
    {
        return success(invStockBillService.viewById(para));
    }

    @PostMapping("/updateBillStatus")
    public AjaxResult updateBillStatus(@RequestBody InvStockBill para)
    {
        return toAjax(invStockBillService.updateBillStatus(para));
    }

}
